<?php

class Model_PostCurl{
	public function send($url,$data='',$tokenId = ''){
		$ch = curl_init();
		curl_setopt($ch,CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_POST, 1);

		$header[] = "Content-Type:application/json;charset=utf-8";
		$header[] = "Connection: keep-alive";
		if($data){
			$header[] = "Content-Length: ".strlen($data);
		}
		
		
		if($tokenId){
			$header[] = "tokenId: $tokenId";
			header("tokenId: $tokenId");
			//curl_setopt($ch, 'tokenId', $tokenId);
		}
		
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
		curl_setopt($ch, CURLOPT_TIMEOUT, 60);
		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)');

		//返回结果
		$content = curl_exec($ch);
		$result = json_decode($content,true);
			
		$code = $result['returnCode'];
		if($code==110 || $code==1){
			$path = $_SERVER['PHP_SELF'];
			header("Location:login.php?path=$path");
			die;
		}
		return $result;
	}
	
	static function wx_send($url,$data=null){
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, $url);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
		if (!empty($data)){
		 curl_setopt($curl, CURLOPT_POST, 1);
		 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
		}
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		$output = curl_exec($curl);
		curl_close($curl);
		return json_decode($output,true);
	}
}

?>